package com.runa.rccprotocol.dto.debao;

import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.ConcentratorRequestData;
import com.runa.rccprotocol.dto.runa.RunaFrameSequence;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DeBaoReadRequestData extends ConcentratorRequestData {

    private byte[] readTime;
    private byte factoryCode;
    private int pn;

    public DeBaoReadRequestData(String address) {
        super(address);
        setHaveResult(true);
    }

    public void readByTime(int pn) {
        this.pn = pn;
        log.debug("readByTime：{} {} ", this.address, this.pn);
    }

    @Override
    public boolean check(IResponseData data) {
        return true;
    }

    @Override
    public byte[] getData() {
        DeBaoRequestData requestData = new DeBaoRequestData(address);
        DeBaoInfo deBaoInfo = DeBaoInfoCache.get(address);
        if (null == deBaoInfo) {
            return null;
        }
        this.readTime = deBaoInfo.getReadTime();
        this.factoryCode = deBaoInfo.getFactoryCode();
        log.debug("getData：{} {} {} {}", this.address, ByteUtil.byteToHexString(this.readTime), this.factoryCode, this.pn);
        requestData.readByTime(readTime, factoryCode, pn, 223);
        log.debug("getData：{} {}", this.address, ByteUtil.byteToHexString(requestData.getData()));
        return requestData.getData();
    }
}
